//
// Created by suzhen on 18-1-16.
//

#pragma once

#include <hacks/net/tcp_acceptor.h>
#include <hacks/net/tcp_conn.h>

namespace hacks::net {

    typedef std::shared_ptr<tcp_acceptor> shared_tcp_acceptor;
    typedef std::map<std::string, shared_tcp_conn> tcp_conn_map;

    class tcp_server {

    public:
        tcp_server(const ip_addr &addr,
                   const std::string &server_name);

    public:
        void start();

    private:
        void on_new_connection(ev_os_sock_t incoming_fd);

    private:
        shared_ev_loop loop_;
        shared_tcp_acceptor shd_acceptor_;
        tcp_conn_map conn_map_;
        std::string s_server_name_;
        std::size_t conn_id_flag_;

    };
}





